package javabase.base.client10.deep.client5;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @author chengshuai
 * @date 2021/5/2 13:41
 */
public class Client5 {

    public static void main(String[] args) throws JsonProcessingException {
        Address address = new Address("杭州", "中国");
        User user = new User("大山", address);
        // 使用Jackson序列化进行深拷贝
        ObjectMapper objectMapper = new ObjectMapper();
        User copyUser = objectMapper.readValue(objectMapper.writeValueAsString(user), User.class);
        // 修改源对象的值
        user.getAddress().setCity("深圳");

        // 检查两个对象的值不同
        System.out.println(user.getAddress().getCity());
        System.out.println(copyUser.getAddress().getCity());
    }
}
